debugfs.rs: Rust API for debugfs#702
Conversation
7d75b10 to
0400797
Compare
| /// Create a new directory in `debugfs` under `parent`. The directory will | ||
| /// be removed when the parent is dropped. | ||
| pub fn create_with_parent<'name, 'parent>( | ||
| name: &'name CStr, |
There was a problem hiding this comment.
if 'name is only used here, wouldn't it be cleaner to elide it?
| ) -> Result<DebugFsFile<T>> { | ||
| let name = name.as_char_ptr(); | ||
| let data = data.into_pointer() as *mut _; | ||
| let parent = parent.map(|p| p.dentry).unwrap_or_else(ptr::null_mut); |
There was a problem hiding this comment.
Is there a reason why you can't use this same sequence (map/unwrap_or_else) to get the parent pointer when creating directories above?
| } | ||
| // SAFETY: `self.data` was created by a call to `T::into_pointer` in | ||
| // [`DebugFsFile::create`]. | ||
| unsafe { T::from_pointer(self.data) }; |
There was a problem hiding this comment.
What happens in the windows between this happening and the parent being dropped?
It seems like we have a dangling pointer in i_private that could, if accessed, lead to UB. Is there anything preventing this?
| /// An `inode` for a file in debugfs with a `T` stored in `i_private`. | ||
| pub struct DebugFsFile<T: PointerWrapper> { | ||
| dentry: *mut bindings::dentry, | ||
| data: *mut c_types::c_void, |
There was a problem hiding this comment.
If the data is stored in the dentry's inode, why do we need to hold a pointer to it here?
| dentry: *mut bindings::dentry, | ||
| has_parent: bool, | ||
| file_children: Vec<Box<dyn Sync>>, | ||
| dir_children: Vec<DebugFsDirectory>, |
There was a problem hiding this comment.
Creating a hierarchy that is recursively dropped in dangerous as it may lead to overflowing the call stack. Is there anything [that I'm failing to see] that prevents recursive calls to drop overflowing the stack? It seems like we need a strategy to clean these up without using recursion to traverse all the elements.
| pub struct DebugFsDirectory { | ||
| dentry: *mut bindings::dentry, | ||
| has_parent: bool, | ||
| file_children: Vec<Box<dyn Sync>>, |
There was a problem hiding this comment.
Is there anything we can do with to_raw_parts that would obviate the need to box the file entries?
We already depend on ptr_metadata.
aa79325 to
d12ec6f
Compare
9d8bad2 to
795d87b
Compare
Add a Rust API to create directories and files in `debugfs`. Signed-off-by: Adam Bratschi-Kaye <ark.email@gmail.com>
Add a Rust API to create directories and files in
debugfs.Signed-off-by: Adam Bratschi-Kaye ark.email@gmail.com